﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
    <script type="text/javascript" src="../Content/highlighter/scripts/shCore.js"></script>
    <script type="text/javascript" src="../Content/highlighter/scripts/shBrushCSharp.js"></script>
    <script type="text/javascript" src="../Content/highlighter/scripts/shBrushXml.js"></script>
    <link type="text/css" rel="stylesheet" href="../Content/highlighter/styles/shCore.css" />
    <link type="text/css" rel="stylesheet" href="../Content/highlighter/styles/shCoreEclipse.css" />
    <script type="text/javascript">SyntaxHighlighter.all();</script>
</head>
<body>
    <h3>控制器实体类生成</h3>
    <p>
        1.新建名称以Controller结尾的控制器IndexController<br/>
        <pre class="brush:csharp;">
            public IndexController : CoreAction
            {
                public void Index()
                {
                    this.ViewBag.Message = "Hello World!";
                    this.ViewBag.Title = "Title";
                }
            }
        </pre>
        2.保存生成该插件，其IndexController下生成了IndexController.model.cs子文件<br/>
        <img src="../Content/images/nfinalcompiler/控制器/控制器生成目录.jpg"/><br />
        生成的源码为：<br/>
        <pre class="brush:csharp;">
            using NFinal;
            //此代码由NFinalControllerGenerator生成。
            //http://bbs.nfinal.com
            namespace NFinalCoreWebSample.Controllers.IndexController_Model
            {
                public class Index
                {
                    [ViewBagMember]
                    [Newtonsoft.Json.JsonIgnore]
                    public NFinal.Collections.FastSearch.FastSearch&lt;NFinal.StringContainer> systemConfig;
                    public string Message;
		            public string Title;
                }
            }
        </pre>
        3.利用属性添加的实体成员<br/>
        以上代码中有systemConfig成员<br />
        该成员在父类中，并带有ViewBagMember属性，该属性指该字段会自动添加进控制器实体类中。<br />
        <img src="../Content/images/nfinalcompiler/控制器/systemConfig.jpg"/><br />
        而Newtonsoft.Json.JsonIgnore是指控制器实体转JSON字符串时，该字段不需要转为Json.<br />
    </p>
</body>
</html>